package com.qjs.activity.rookie.exception;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class ControllerHandler {
	public static final Logger log = LoggerFactory.getLogger(ControllerHandler.class);

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public Map handlerError(HttpServletRequest req, Exception e) {
		System.out.println("1:" + e);
		System.out.println("2:" + e.getMessage());
		Map<String, String> map = new HashMap<String, String>();
		map.put("tip", "此错误说明调用接口失败，失败原因见msg，如果msg为空，联系后台");
		return map;
	}

	
	@ExceptionHandler(NullPointerException.class)
	@ResponseBody
	public Map handlerError2(HttpServletRequest req, Exception e) {
		System.out.println("1:" + e);
		System.out.println("2:" + e.getMessage());
		Map<String, String> map = new HashMap<String, String>();
		map.put("tip", "nukk");
		return map;
	}
	
	
	@ExceptionHandler(MyException.class)
	public ModelAndView busError(HttpServletRequest req, Exception e) {
		System.out.println("1:" + e);
		System.out.println("2:" + e.getMessage());
		ModelAndView vm = new ModelAndView();
		Map<String, String> map = new HashMap<String, String>();
		map.put("tip", "此错误说明调用接口失败");
		vm.setViewName("500");
		return vm;

	}

}
